<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vue Router 基础</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script src="https://unpkg.com/vue-router@4/dist/vue-router.global.js"></script>
    <style>
      body {
        font-family: Arial, sans-serif;
        max-width: 800px;
        margin: 0 auto;
        padding: 20px;
      }
      .router-link-active {
        color: #42b983;
        font-weight: bold;
      }
      .page {
        border: 1px solid #ddd;
        border-radius: 4px;
        padding: 20px;
        margin-top: 20px;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <h1>Vue Router 基础</h1>
      <p>
        <router-link to="/">首页</router-link> | 
        <router-link to="/about">关于</router-link>
      </p>
      <router-view></router-view>
    </div>

    <script>
      // 1. 定义路由组件
      const Home = { template: '<div class="page">这是首页内容</div>' }
      const About = { template: '<div class="page">这是关于页面内容</div>' }

      // 2. 定义路由
      const routes = [
        { path: '/', component: Home },
        { path: '/about', component: About },
      ]

      // 3. 创建路由实例
      const router = VueRouter.createRouter({
        history: VueRouter.createWebHashHistory(),
        routes,
      })

      // 4. 创建并挂载根实例
      const app = Vue.createApp({})
      
      // 确保使用路由实例
      app.use(router)
      
      // 挂载应用
      app.mount('#app')
    </script>
  </body>
</html> 